/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package classi;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author sestari
 */
public class faLogin {

    Connection con;

    public faLogin(Connection c) {
        this.con = c;
    }
    public faLogin(){
        
    }

    
    //Classe utilizzata per fare il login
    public utente Login(String username, String password) {
        ResultSet rs = null;
        String comand = "select id, nome, medico, cognome from Persone where  username = \"" + username + "\" and password=\"" + password + "\"";

        Statement st;
        try {
            st = (Statement) con.createStatement();
            rs = (ResultSet) st.executeQuery(comand);
            if (rs.next()) {

                utente uten = new utente();


                uten.setId(rs.getInt(1));
                uten.setNome(rs.getString(2));
                uten.setUsername(username);
                uten.setMedico(rs.getInt(3));
                uten.setCognome(rs.getString(4));
                return uten;
            }

        } catch (SQLException ex) {
            Logger.getLogger(faLogin.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;


    }
    
    
    //classe per prendere la data e l'ora attuale
     public String getDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date date = new Date();
        return dateFormat.format(date);
    }
}
